Developer Documentation

QuickTime 4 API Documentation

QuickTime For Windows Programmers

| Previous | Chapter Contents | Chapter Top | Roadmap | Next |

QuickTime for Windows: A Quick Start

Incorporating the QuickTime routines into the structure of a Windows application program is relatively straightforward. You need to follow the basic steps outlined here to build a simple QuickTime capability into your Windows program. Names in parentheses are those of the relevant QTML routines.

  1. Initialize the QuickTime Media Layer ( InitializeQTML ) and QuickTime ( EnterMovies ) at the start of your program.
  2. Associate a QuickDraw graphics port with your movie window ( CreatePortAssociation ).
  3. Open a movie file ( OpenMovieFile ) and extract the movie from it ( NewMovieFromFile ).
  4. Create a movie controller for displaying the movie on the screen ( NewMovieController ).
  5. In your window procedure, convert incoming messages to QTML events ( WinEventToMacEvent ) and pass them to the movie controller for processing ( MCIsPlayerEvent ).
  6. Dispose of the movie ( DisposeMovie ) and its controller ( DisposeMovieController ) when they're no longer needed.
  7. Dispose of your movie window's graphics port when the window is destroyed ( DestroyPortAssociation ).
  8. Terminate QuickTime ( ExitMovies ) and the QuickTime Media Layer ( TerminateQTML ) at the end of your program.

Listing 1 illustrates, in skeletal form, how these steps fit into the structure of a typical Windows application program. In the next chapter, we'll discuss each of these steps in turn, along with the related QTML concepts that you need to understand in order to use QuickTime effectively.

Listing 1 Skeleton of a Windows program using QuickTime

// Resource identifiers
             ·
             ·
#define IDM_OPEN 101
             ·
             ·

// Global variables

    char movieFile[255];                // Name of movie file
    Movie theMovie;                      // Movie object
    MovieController theMC;                         // Movie controller

///////////////////////////////////////////////////////////////////////////////////////

int CALLBACK WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
         LPSTR lpCmdLine, int nCmdShow)
    
    {
            ·
            ·
        InitializeQTML(0);                          // Initialize QTML
        EnterMovies();                              // Initialize QuickTime
            ·
            ·
        ///////////////////////////////////////////////////////////////////////////////
        // Main message loop
                ·
                ·
        //
        ///////////////////////////////////////////////////////////////////////////////
            ·
            ·
        ExitMovies();                               // Terminate QuickTime
        TerminateQTML();                            // Terminate QTML
        
    } /* end WinMain */

///////////////////////////////////////////////////////////////////////////////////////

LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    
    {
        MSG  winMsg;
        EventRecord qtmlEvent;
        int          wmEvent, wmId;
        
     // Fill in contents of MSG structure
                ·
                ·
        
        NativeEventToMacEvent (&winMsg, &qtmlEvent);// Convert message to a QTML event
                    
        MCIsPlayerEvent (theMC, (const EventRecord *) &qtmlEvent);
                                                    // Pass event to movie controller
        switch ( message )
            {   
                case WM_CREATE:
                    CreatePortAssociation (hWnd, NULL); // Register window with QTML
                    break;
                    
                case WM_COMMAND:
                    wmEvent = HIWORD(wParam);           // Parse menu selection
                    wmId = LOWORD(wParam);
                        
                    switch ( wmId )
                        {   
                            case IDM_OPEN:
                                CloseMovie ();          // Close previous movie, if any
                                
                                if ( GetFile (movieFile) )  // Get file name from user
                                    OpenMovie (hWnd, movieFile);    // Open the movie
                                break;
                            
                                    ·
                                    ·
                                
                            default:
                                return DefWindowProc (hWnd, message,
                                                     wParam, lParam);
                            
                        } /* end switch ( wmId ) */
                    
                    break;
                    
                case WM_CLOSE:
                    DestroyPortAssociation (hWnd);      // Unregister window with QTML
                    break;
                    
                        ·
                        ·
                    
                default:
                    return DefWindowProc (hWnd, message, wParam, lParam);
                
            } /* end switch ( message ) */
        
        return 0;
        
    } /* end WndProc */

///////////////////////////////////////////////////////////////////////////////////////

BOOL GetFile (char *movieFile)
    
    {
     OPENFILENAME ofn;
        
     // Fill in contents of OPENFILENAME structure
                ·
                ·
        
     if ( GetOpenFileName(&ofn) )                // Let user select file
     return TRUE;
        else
     return FALSE;
        
    } /* end GetFile */


///////////////////////////////////////////////////////////////////////////////////////

void OpenMovie (HWND hwnd, char fileName[255])
    
    {
        short theFile = 0;
        FSSpec sfFile;
        char fullPath[255];
        
        SetGWorld ( (CGrafPtr)GetNativeWindowPort( hwnd ), nil); // Set graphics port
        
        strcpy (fullPath, fileName);                        // Copy full pathname
        c2pstr (fullPath);                                  // Convert to Pascal string
        
        FSMakeFSSpec (0, 0L, fullPath, &sfFile);            // Make file-system
                                                            // specification record
        
        OpenMovieFile (&sfFile, &theFile, fsRdPerm);        // Open movie file
        NewMovieFromFile (&theMovie, theFile, nil,          // Get movie from file
                         nil, newMovieActive, nil);
        
        CloseMovieFile (theFile);                           // Close movie file
        
        theMC = NewMovieController (theMovie, ... );        // Make movie controller
            ·
            ·
        
    } /* end OpenMovie */

///////////////////////////////////////////////////////////////////////////////////////

void CloseMovie (void)
    
    {   
        if ( theMC )                            // Destroy movie controller, if any
            DisposeMovieController (theMC);
        
        if ( theMovie )                         // Destroy movie object, if any
            DisposeMovie (theMovie);
        
    } /* end CloseMovie */

© 1998 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Roadmap | Next |